package gold.digger;

/**
 * Created by fanzhenyu02 on 2020/3/1.
 */
public class LC66 {

    public int[] plusOne(int[] digits) {
        boolean step = true;
        for (int i = digits.length - 1; i >= 0; i--) {
            if (step) {
                digits[i] += 1;
                if (digits[i] > 9) {
                    digits[i] = 0;
                } else {
                    step = false;
                    break;
                }
            } else {
                step = false;
                break;
            }
        }

        if (step) {
            int[] newDigits = new int[digits.length + 1];
            newDigits[0] = 1;
            return newDigits;
        }

        return digits;
    }


    public static void main(String[] args) {
        LC66 an = new LC66();
        int[] arr = {4, 3, 2, 9};

        System.out.println(an.plusOne(arr));
    }
}
